package com.kucowka.otc.util.queue;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import com.kucowka.otc.util.heap.MaxHeap;

public class SimplePriorityQueue<T extends Comparable<T>> implements
		PriorityQueue<T> {

	private final MaxHeap<T> maxHeap;
	private final Lock lock = new ReentrantLock();

	public SimplePriorityQueue(MaxHeap<T> maxHeap) {
		this.maxHeap = maxHeap;
	}

	public int size() {
		lock.lock();
		int size = maxHeap.size();
		lock.unlock();
		return size;
	}

	public void insert(T element) {
		lock.lock();
		maxHeap.add(element);
		lock.unlock();
	}

	public T popMax() {
		lock.lock();
		T t = maxHeap.pop();
		lock.unlock();
		return t;
	}

}
